# $Id: Makefile 1485 2007-01-04 23:08:52Z andres $ 
# Compilers
SHELL = /bin/sh
VPATH = @srcdir@

subdirs=@subdirs@
top_srcdir = @top_srcdir@
srcdir = @srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
infodir = $(prefix)/info
libdir = $(prefix)/lib/gnudl
mandir = @mandir@/man1

CC = @CC@
CPPFLAGS = @CPPFLAGS@
CFLAGS = $(CPPFLAGS) @CFLAGS@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
INSTALL = @INSTALL@
MKDIR_P = @MKDIR_P@
USEPARALLEL := @USEPARALLEL@
USE_LARGE_MESSAGES := @USE_LARGE_MESSAGES@
OCAML = @OCAML@
OCAMLBUILD := @OCAMLBUILD@

SUBDIRS = src 

all: poy.native VERSION

poy_test.native:
	cd ./src/; $(OCAMLBUILD) poy_test.native
	cp ./src/poy_test.native ./test/poy_test.native

portal.native: poy.native xml/swami.xml 
	cd src; $(OCAMLBUILD) portal.native

portal: portal.native

src/makeVersion.native:
	cd src; $(OCAMLBUILD) makeVersion.native

xml/swami.xml: src/makeVersion.native
	export RESULT="`src/makeVersion.native -text`"; sed "s/VERSION/$${RESULT}/g" xml/swami.xml.in > xml/swami.xml

VERSION: src/makeVersion.native 
	export RESULT="`src/makeVersion.native -text`"; echo "POY $${RESULT}" > VERSION

.PHONY:	portal.native poy $(SUBDIRS) clean install distclean VERSION doc

subdirs: $(SUBDIRS)

transform = @program_transform_name@

install: poy.native
	$(MKDIR_P) $(DESTDIR)$(bindir)
	$(INSTALL) ./src/_build/poy.native $(DESTDIR)$(bindir)/`echo poy | sed -e '$(transform)'`
	$(MKDIR_P) $(DESTDIR)$(mandir)
	$(INSTALL) ./src/_build/poy.1 $(DESTDIR)$(mandir)/poy.1

install_server: install portal.native
	$(INSTALL) ./src/_build/portal.native $(DESTDIR)$(bindir)/`echo portal | sed -e '$(transform)'` 

uninstall:
	rm -f $(bindir)/`echo poy | sed '$(transform)'`

poy.native: 
	cd src; \
	$(MAKE) $@

poy: poy.native
	cp src/_build/poy.native src/poy

doc: 
	cd src; \
	$(OCAMLBUILD) commands.pdf
	cp src/_build/commands.pdf ./manual.pdf

poy.byte:
	cd src; \
	$(MAKE) $@

poy.top:
	cd src; \
	$(MAKE) $@

clean:
	rm -f plugins/*.cm* plugins/*.o
	@for subs in $(SUBDIRS); do \
	  cd $$subs; \
	  $(MAKE) clean; \
	  cd ..; \
	done

distclean: clean
	rm -f config.log
	rm -f config.status
	rm -f test/poy_test*
	@for subs in $(SUBDIRS); do \
	  cd $$subs; \
	  $(MAKE) distclean; \
	  cd ..; \
	done
	rm -f Makefile
